﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Ponguizinho.Game.PONG
{
    class PongGame
    {
        private Paleta p1, p2;
        private Bola bola;
        public PongGame(ContentManager Content)
        {
            p1 = new Paleta(Content.Load<Texture2D>("p1"), 1, new Vector2(0, 0), Paleta.ModoInteracao.LETRAS);
            p2 = new Paleta(Content.Load<Texture2D>("p1"), 1, 
                new Vector2(Game1.LARGURATELA - Content.Load<Texture2D>("p1").Width, 0), Paleta.ModoInteracao.SETAS);

            bola = new Bola(Content.Load<Texture2D>("bola"), new Vector2(Game1.LARGURATELA / 2, Game1.ALTURATELA / 2), new Vector2(-0.2f, -0.2f));
        }
        public void Update(GameTime gameTime)
        {
            p1.Update(gameTime);
            p2.Update(gameTime);
            Rectangle[] retanguloTemporario = new Rectangle[2];
            retanguloTemporario[0] = p1.RETANGULO;
            retanguloTemporario[1] = p2.RETANGULO;
            bola.Update(gameTime, VerificarColisao(bola.RETANGULO, retanguloTemporario));
        }
        public void Draw(SpriteBatch spriteBatch)
        {
            p1.Draw(spriteBatch);
            p2.Draw(spriteBatch);
            bola.Draw(spriteBatch);
        }

        private bool VerificarColisao(Rectangle obj1, Rectangle[] obj2)
        {
            for (int indice = 0; indice < obj2.Length; indice++)
            {
                if (obj1.Intersects(obj2[indice]))
                    return true;
            }

            return false;
        }
    }
}
